home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / amiexpress / source / ae / code / ax3.00 / readchar.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-01-03  |  9.8 KB  |  545 lines

  1. #include "bbs.h"
  2.  
  3. extern int CHATF, ChatSerFlag,ChatConFlag;
  4. //extern UBYTE GUB1;
  5. extern UBYTE serin[],conin[];
  6. int BypassCSI=0;
  7. int XIMPort=0;
  8.  
  9. //int CheckSerCSI(void);   remove from console.c
  10.  
  11. static int readser(ULONG wait)
  12. {
  13.  UBYTE gub1;
  14.  
  15.  if(SEROUT) {
  16.         SetTimer(wait,0L); /* wait for n seconds */
  17.         while(TRUE)    {
  18.             Wait( SerCharSig | TimerSig);
  19.             if(CheckSer()) {
  20.                 AbortIO(TimerMsg);
  21.                 WaitIO(TimerMsg);
  22.                 WaitIO(ReadSerReq);
  23.                 gub1 = (int)serin[0];
  24.                 SendIO(ReadSerReq);
  25.                 return((int)gub1);
  26.             }
  27.             if(CheckIO(TimerMsg)) {
  28.                 WaitIO(TimerMsg);
  29.                 return(TIMEOUT);
  30.             }
  31.         }
  32.     }
  33.  return(SUCCESS);
  34. }
  35.  
  36. static int CheckSerCSI(void)
  37. {
  38.  extern UBYTE NumHistItems,WhichHist;
  39.  extern long DoHistory,LineHasChanged;
  40.  extern int  HistorySelect;
  41.  
  42.  int ch;
  43.  
  44.  ch=readser(3L);
  45.  if(ch=='[')    {
  46.         ch=readser(3L);
  47.         if((!DoHistory)||NumHistItems==0)
  48.          {
  49.            if((ch>='A' )&&(ch<'E')&&!RawArrow)    return(FALSE);
  50.          }
  51.         if(ch=='A') {
  52.           if(RawArrow) return(UPARROW);
  53.             HistorySelect--;
  54.             if(HistorySelect<0)    {
  55.                 if(NumHistItems==MAXHIST)    HistorySelect=MAXHIST-1;
  56.                 else {
  57.                     HistorySelect=0;
  58.                     if(LineHasChanged)    {
  59.                         LineHasChanged=0;
  60.                         return(HISTORY);
  61.                     }
  62.                     return(FAILURE);
  63.                 }
  64.             }
  65.             return(HISTORY);
  66.         }
  67.  
  68.         if(ch=='B')    {
  69.  if(RawArrow) return(DOWNARROW);
  70.     
  71.             HistorySelect++;
  72.             if(NumHistItems!=MAXHIST) {
  73.                 if(HistorySelect>=WhichHist) {
  74.                     HistorySelect--;
  75.                     if(LineHasChanged)    {
  76.                         LineHasChanged=0;
  77.                         return(HISTORY);
  78.                     }
  79.                     return(FAILURE);
  80.                 }
  81.             } else {
  82.                 if(HistorySelect>=MAXHIST)        HistorySelect=0;
  83.             }
  84.             return(HISTORY);
  85.         }
  86. if(ch=='C'||ch=='D')
  87.     {
  88.        if(RawArrow)
  89.        {
  90.          if(ch=='C')return(LEFTARROW);
  91.          return(RIGHTARROW);
  92.        }
  93.     return(FALSE);
  94.     }
  95.  
  96.     }
  97. return(FALSE);
  98. }
  99. int ReadChar(ULONG wait)
  100. {
  101. int ch,flag;
  102. long sig;
  103. BOOL SERVERCMD;
  104. //char hex[8];
  105.  
  106. flag=0;
  107. if((long)wait>70L)
  108.     {
  109.     flag=1;
  110.     wait=wait-60L;
  111.     }
  112.  
  113. ChatConFlag=0;
  114. ChatSerFlag=0;
  115. SetTimer((long)wait,0L);
  116. FOREVER
  117.     {
  118.     if(KEYIN)
  119.         {
  120.         if(SEROUT)
  121.             {
  122.             sig=Wait(SerCharSig | ConCharSig | TimerSig | IconifySig | RexxSig | DoorSig);
  123.             }
  124.         else
  125.             {
  126.             sig=Wait(ConCharSig | TimerSig | IconifySig | RexxSig | DoorSig);
  127.             }
  128.         }
  129.     else
  130.         {
  131.         if(SEROUT)
  132.                {
  133.                sig=Wait(SerCharSig | TimerSig | IconifySig | DoorSig | RexxSig);
  134.             }
  135.         else
  136.             {
  137.             sig=Wait(TimerSig | IconifySig | DoorSig | RexxSig);
  138.             }
  139.         }
  140. OneMin:
  141.     if(Whence_The_Logon==REMOTE_LOGON)
  142.         {
  143.         GI1=CheckCarrier();
  144.         if(GI1==FALSE)
  145.             {
  146.             AbortIO(TimerMsg);
  147.             WaitIO(TimerMsg);
  148.             return(NO_CARRIER);
  149.             }
  150.         }
  151.         if(CheckSer())
  152.         {
  153.           XIMPort=SERIAL_PORT;
  154.         AbortIO(TimerMsg);
  155.         WaitIO(TimerMsg);
  156.         WaitIO(ReadSerReq);
  157.         ch = (int)serin[0];
  158.         SendIO(ReadSerReq);
  159.         if(IO_Flags[IOFLAG_SER_IN]>0)
  160.             {
  161.             ChatSerFlag=1;
  162.             if(ch == 27)
  163.                 {
  164.                     if(BypassCSI) return(ch);
  165.                 GI1=CheckSerCSI();
  166.                     switch(GI1)
  167.                     {
  168.                          case HISTORY:
  169.                               return(HISTORY);
  170.                          case LEFTARROW:
  171.                          case RIGHTARROW:
  172.                          case UPARROW:
  173.                          case DOWNARROW:
  174.                               return(GI1);
  175.                     }
  176.                 SetTimer(wait,0L);
  177.                 goto OneMin;//goto OneMin;
  178.                 }
  179.     
  180.             return(ch);
  181.             }
  182.         else
  183.             {
  184.             if(Whence_The_Logon!=REMOTE_LOGON)
  185.                 {
  186. PurgeLine();
  187.                 return(0);
  188.                 }
  189.             SetTimer(wait,0L);
  190.             flag=1;
  191.             goto OneMin;
  192.             }
  193.         }
  194.         if(CheckCon())
  195.             {
  196.                XIMPort=CONSOLE_PORT;
  197.             AbortIO(TimerMsg);
  198.             WaitIO(TimerMsg);
  199.             WaitIO(ReadConReq);
  200.             ch = (int)conin[0];
  201.             SendIO(ReadConReq);
  202.             if(ch == CSI)
  203.                 {
  204.                     if(BypassCSI) return(ch);
  205.                 GI1=CheckCSI();
  206.                 switch(GI1)
  207.                     {
  208.                     case HISTORY:
  209.                         return(HISTORY);
  210.                     case NO_CARRIER:
  211.                         return(GI1);
  212.                     case EXITCHAT:
  213.                         return(0);
  214.                     case 1:
  215.                         if(CHATF==1)
  216.                             {
  217.                             return(13);
  218.                             }
  219.                         return(0);
  220.                         break;
  221.                     case 0:
  222.                         if(wait==1)
  223.                             {
  224.                             return(0);
  225.                             }
  226.                         break;
  227.                          case LEFTARROW:
  228.                          case RIGHTARROW:
  229.                          case UPARROW:
  230.                          case DOWNARROW:
  231.                               return(GI1);
  232.                     }
  233.                 SetTimer(wait,0L);
  234.                 goto OneMin;
  235.                 }
  236.             ChatConFlag=1;
  237.             return(ch);
  238.             }
  239.  
  240.     
  241.     if(CheckIO(TimerMsg))
  242.         {
  243.         WaitIO(TimerMsg);
  244.         if(flag==1)
  245.             {
  246.             if(!Sopt->Toggles[4])SendChar('\07');
  247.             wait=60L;
  248.             SetTimer(wait,0L);
  249.             if(!Sopt->Toggles[4]) flag=0; 
  250.                goto OneMin; 
  251.  
  252.             }
  253.         return(TIMEOUT);
  254.         }
  255.     
  256.      SERVERCMD=CheckDoorMsg(1);
  257.      if(SERVERCMD)
  258.         {
  259.           AbortIO(TimerMsg);
  260.           WaitIO(TimerMsg);
  261.            if(ServerCmd)
  262.            {
  263.               switch(ServerCmd)
  264.               {
  265.                     case SV_CHAT:
  266.                     CHATF=1;
  267.                 ChatFlag=!ChatFlag;
  268.                 if(ChatFlag==0) { return(0); }
  269.                     SetEnvStat(ENV_CHAT);
  270.                 if(Chat()==NO_CARRIER)
  271.                     {
  272.                     return(NO_CARRIER);
  273.                     }
  274.                     
  275.                     break;
  276.               }
  277.               ServerCmd=0;
  278.             }
  279.           ch = (int)serverin[0];
  280.           if(ch == CSI)
  281.             {
  282.             GI1=CheckCSI();
  283.             switch(GI1)
  284.                 {
  285.                 case HISTORY:
  286.                     return(HISTORY);
  287.                 case NO_CARRIER:
  288.                     return(GI1);
  289.                 case EXITCHAT:
  290.                     return(0);
  291.                 case 1:
  292.                     if(CHATF==1)
  293.                         {
  294.                         return(13);
  295.                         }
  296.                     return(0);
  297.                     break;
  298.                 case 0:
  299.                     if(wait==1)
  300.                         {
  301.                         return(0);
  302.                         }
  303.                     break;
  304.                          case LEFTARROW:
  305.                          case RIGHTARROW:
  306.                          case UPARROW:
  307.                          case DOWNARROW:
  308.                               return(GI1);
  309.                 }
  310.             SetTimer(wait,0L);
  311.             goto OneMin;
  312.             }
  313.         ChatConFlag=1;
  314.         return(ch);
  315.             
  316.         }
  317.      
  318.     CheckIconifyMsg(); 
  319.     CheckRexxMessage();
  320.         
  321.         
  322.     }
  323. return(SUCCESS);
  324. }
  325. int ReadExtChar(ULONG wait,ULONG mysig)
  326. {
  327. int ch,flag;
  328. long sig;
  329. BOOL SERVERCMD;
  330. //char hex[8];
  331.  
  332. flag=0;
  333. if((long)wait>70L)
  334.     {
  335.     flag=1;
  336.     wait=wait-60L;
  337.     }
  338.  
  339. ChatConFlag=0;
  340. ChatSerFlag=0;
  341. SetTimer((long)wait,0L);
  342. FOREVER
  343.     {
  344.     if(KEYIN)
  345.         {
  346.         if(SEROUT)
  347.             {
  348.             sig=Wait(SerCharSig | ConCharSig | TimerSig | IconifySig | RexxSig | DoorSig | mysig);
  349.             }
  350.         else
  351.             {
  352.             sig=Wait(ConCharSig | TimerSig | IconifySig | RexxSig | DoorSig | mysig);
  353.             }
  354.         }
  355.     else
  356.         {
  357.         if(SEROUT)
  358.                {
  359.                sig=Wait(SerCharSig | TimerSig | IconifySig | DoorSig | RexxSig | mysig);
  360.             }
  361.         else
  362.             {
  363.             sig=Wait(TimerSig | IconifySig | DoorSig | RexxSig | mysig);
  364.             }
  365.         }
  366.           if(sig&mysig) { SetTimer(wait,0L); return(0);}
  367. OneMin:
  368.     if(Whence_The_Logon==REMOTE_LOGON)
  369.         {
  370.         GI1=CheckCarrier();
  371.         if(GI1==FALSE)
  372.             {
  373.             AbortIO(TimerMsg);
  374.             WaitIO(TimerMsg);
  375.             return(NO_CARRIER);
  376.             }
  377.         }
  378.         if(CheckSer())
  379.         {
  380.         AbortIO(TimerMsg);
  381.         WaitIO(TimerMsg);
  382.         WaitIO(ReadSerReq);
  383.         ch = (int)serin[0];
  384.         SendIO(ReadSerReq);
  385.         if(IO_Flags[IOFLAG_SER_IN]>0)
  386.             {
  387.             ChatSerFlag=1;
  388.             if(ch == 27)
  389.                 {
  390.                 if((GI1=CheckSerCSI())==HISTORY)
  391.                     {
  392.                     return(HISTORY);
  393.                     }
  394.                     switch(GI1)
  395.                     {
  396.                          case LEFTARROW:
  397.                          case RIGHTARROW:
  398.                          case UPARROW:
  399.                          case DOWNARROW:
  400.                               return(GI1);
  401.                     }
  402.                 SetTimer(wait,0L);
  403.                 goto OneMin;//goto OneMin;
  404.                 }
  405.     
  406.             return(ch);
  407.             }
  408.         else
  409.             {
  410.             if(Whence_The_Logon!=REMOTE_LOGON)
  411.                 {
  412. PurgeLine();
  413.                 return(0);
  414.                 }
  415.             SetTimer(wait,0L);
  416.             flag=1;
  417.             goto OneMin;
  418.             }
  419.         }
  420.         if(CheckCon())
  421.             {
  422.             AbortIO(TimerMsg);
  423.             WaitIO(TimerMsg);
  424.             WaitIO(ReadConReq);
  425.             ch = (int)conin[0];
  426.             SendIO(ReadConReq);
  427.             if(ch == CSI)
  428.                 {
  429.                 GI1=CheckCSI();
  430.                 switch(GI1)
  431.                     {
  432.                     case HISTORY:
  433.                         return(HISTORY);
  434.                     case NO_CARRIER:
  435.                         return(GI1);
  436.                     case EXITCHAT:
  437.                         return(0);
  438.                     case 1:
  439.                         if(CHATF==1)
  440.                             {
  441.                             return(13);
  442.                             }
  443.                         return(0);
  444.                         break;
  445.                     case 0:
  446.                         if(wait==1)
  447.                             {
  448.                             return(0);
  449.                             }
  450.                         break;
  451.                          case LEFTARROW:
  452.                          case RIGHTARROW:
  453.                          case UPARROW:
  454.                          case DOWNARROW:
  455.                               return(GI1);
  456.                     }
  457.                 SetTimer(wait,0L);
  458.                 goto OneMin;
  459.                 }
  460.             ChatConFlag=1;
  461.             return(ch);
  462.             }
  463.  
  464.     
  465.     if(CheckIO(TimerMsg))
  466.         {
  467.         WaitIO(TimerMsg);
  468.         if(flag==1)
  469.             {
  470.             if(!Sopt->Toggles[4])SendChar('\07');
  471.             wait=60L;
  472.             SetTimer(wait,0L);
  473.             if(!Sopt->Toggles[4])flag=0;
  474.             goto OneMin;
  475.             }
  476.         return(TIMEOUT);
  477.         }
  478.      SERVERCMD=CheckDoorMsg(1);
  479.      if(SERVERCMD)
  480.         {
  481.           AbortIO(TimerMsg);
  482.           WaitIO(TimerMsg);
  483.            if(ServerCmd)
  484.            {
  485.               switch(ServerCmd)
  486.               {
  487.                     case SV_CHAT:
  488.                     CHATF=1;
  489.                 ChatFlag=!ChatFlag;
  490.                 if(ChatFlag==0) { return(0); }
  491.                     SetEnvStat(ENV_CHAT);
  492.                 if(Chat()==NO_CARRIER)
  493.                     {
  494.                     return(NO_CARRIER);
  495.                     }
  496.                     
  497.                     break;
  498.               }
  499.               ServerCmd=0;
  500.             }
  501.           ch = (int)serverin[0];
  502.           if(ch == CSI)
  503.             {
  504.             GI1=CheckCSI();
  505.             switch(GI1)
  506.                 {
  507.                 case HISTORY:
  508.                     return(HISTORY);
  509.                 case NO_CARRIER:
  510.                     return(GI1);
  511.                 case EXITCHAT:
  512.                     return(0);
  513.                 case 1:
  514.                     if(CHATF==1)
  515.                         {
  516.                         return(13);
  517.                         }
  518.                     return(0);
  519.                     break;
  520.                 case 0:
  521.                     if(wait==1)
  522.                         {
  523.                         return(0);
  524.                         }
  525.                     break;
  526.                          case LEFTARROW:
  527.                          case RIGHTARROW:
  528.                          case UPARROW:
  529.                          case DOWNARROW:
  530.                               return(GI1);
  531.                 }
  532.             SetTimer(wait,0L);
  533.             goto OneMin;
  534.             }
  535.         ChatConFlag=1;
  536.         return(ch);
  537.             
  538.         }
  539.     CheckIconifyMsg(); 
  540.     CheckRexxMessage();
  541.         
  542.         
  543.     }
  544. return(SUCCESS);
  545. }